<template>
    <el-dialog title="奖惩建议申请单" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true"
        class="SHZY-dialog SHZY-dialog_center" lock-scroll width="80%">
        <el-row :gutter="15" class="" :style="{ margin: '0 auto', width: '100%' }">
            <el-form ref="elForm" size="small" label-width="100px" label-position="left" :model="dataForm"
                :rules="rules">
                <el-col :span="6">
                    <el-form-item label="工号/姓名" prop="samplingType">
                        <el-select v-model="dataForm.samplingType" placeholder="抽样方案" clearable>
                            <el-option v-for="(item, index) in sampleTypeData" :key="index" :label="item.fullName"
                                :value="item.enCode" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="部门" prop="no">
                        <el-input v-model='dataForm.no' placeholder='请输入' clearable :style='{ "width": "100%" }'>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="岗位" prop="no">
                        <el-input v-model='dataForm.no' placeholder='请输入' clearable :style='{ "width": "100%" }'>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="管理归属公司" prop="no">
                        <el-input v-model='dataForm.no' placeholder='请输入' clearable :style='{ "width": "100%" }'>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <groupTitle content-position="left" content="奖励类别">
                        </groupTitle>
                    </el-form-item>
                </el-col>
                <el-col :span="24">

                    <el-form-item label-width="0">
                        <el-checkbox-group v-model="awardListType" style="display: flex;">
                            <el-checkbox label="1.嘉奖"></el-checkbox>
                            <el-checkbox label="2.先进集体"></el-checkbox>
                            <el-checkbox label="3.先进个人"></el-checkbox>
                            <el-checkbox label="4.自查互纠"></el-checkbox>
                            <div style="display: flex;margin-left: 20px">
                                <el-checkbox label="5.其他"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px;margin-left: 10px;">
                                </el-input>
                            </div>
                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <groupTitle content-position="left" content="奖励形式">
                        </groupTitle>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <el-checkbox-group v-model="awardListModality" style="display: flex;">
                            <div style="display: flex;">
                                <el-checkbox label="1.奖励现金（工资下发）"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable style="width: 100px;">
                                </el-input>
                            </div>
                            <div style="display: flex; margin-left: 10px;">

                                <el-checkbox label="2.奖品"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px; margin-left: 10px;">
                                </el-input>
                                <el-input v-text="text1" style=" width: 40px; margin-left: 10px;">
                                </el-input>

                            </div>
                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="3.代金券"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px; margin-left: 10px;">
                                </el-input>
                                <el-input v-text="text2" style=" width: 40px; margin-left: 10px;">
                                </el-input>
                            </div>
                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="4.其他形式"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px;margin-left: 10px;">
                                </el-input>
                            </div>
                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <groupTitle content-position="left" content="处罚类别">
                        </groupTitle>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <el-checkbox-group v-model="punishListType" style="display: flex;">
                            <el-checkbox label="1.警告(口头警告、教育、写检讨)"></el-checkbox>
                            <el-checkbox label="2.现金处罚"></el-checkbox>
                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="3.其他"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px;margin-left: 10px;">
                                </el-input>
                            </div>

                        </el-checkbox-group>
                    </el-form-item>
                </el-col>

                <el-col :span="24">
                    <el-form-item label-width="0">
                        <groupTitle content-position="left" content="处罚形式">
                        </groupTitle>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <el-checkbox-group v-model="punishListModality" style="display: flex;">

                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="1.处罚现金（工资中扣）"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px; margin-left: 10px;">
                                </el-input>
                                <el-input v-text="text2" style=" width: 40px; margin-left: 10px;">
                                </el-input>
                            </div>

                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="2.代金券（扣）"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px; margin-left: 10px;">
                                </el-input>
                                <el-input v-text="text2" style=" width: 40px; margin-left: 10px;">
                                </el-input>
                            </div>
                            <div style="display: flex; margin-left: 10px;">
                                <el-checkbox label="3.其他形式"></el-checkbox>
                                <el-input v-model='dataForm.no' placeholder='请输入' clearable
                                    style="width: 100px;margin-left: 10px;">
                                </el-input>
                            </div>

                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="0">
                        <groupTitle content-position="left" content="">
                        </groupTitle>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="奖惩公布范围">
                        <el-checkbox-group v-model="publishScope" style="display: flex;">
                            <el-checkbox label="不公布"></el-checkbox>
                            <el-checkbox label="部门范围内"></el-checkbox>
                            <el-checkbox label="公司范围内"></el-checkbox>
                            <el-checkbox label="企业范围内"></el-checkbox>

                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="奖惩公布形式">
                        <el-checkbox-group v-model="publishModality" style="display: flex;">
                            <el-checkbox label="早会宣布"></el-checkbox>
                            <el-checkbox label="张贴通报"></el-checkbox>
                            <el-checkbox label="宣布并张贴"></el-checkbox>
                            <el-checkbox label="其他"></el-checkbox>

                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="200" label="奖惩事实说明（需包含时间、地点、人员、事件、结果）：">
                     
                        <el-input v-model='dataForm.problemDescription' type="textarea" maxlength="500" show-word-limit
                            placeholder='请输入' clearable :style='{ "width": "100%" }' :rows="3">
                        </el-input>
                    </el-form-item>

                </el-col>
            </el-form>
        </el-row>

        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">{{ $t('common.cancelButton') }}</el-button>
            <el-button :loading="btnLoading" type="primary" @click="dataFormSubmit()">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>

import { addInspectionitem } from '@/api/q1/business/inspectionLot'
export default {
    data() {
        return {
            btnLoading: false,
            visible: false,



            dataForm:
            {
                sampleTypeData: '',
                other: ''

            },
            rules: {

            },
            text1: '(价值)',
            text2: '元',
            text3: '奖惩事实说明（需包含时间、地点、人员、事件、结果）：',
            awardListType: [],//奖励类别
            awardListModality: [],//奖励形式
            punishListType: [],//处罚类别
            punishListModality: [],//处罚形式
            publishScope: [],//奖惩公布范围
            publishModality: []//奖惩公布形式

        }
    },
    created() {
        this.getDictionaryData();
    },
    methods: {
        getDictionaryData() {
            this.$store.dispatch('base/getDictionaryData', { sort: 'sampleType' }).then((res) => {
                this.sampleTypeData = res
            })

        },
        init() {
            this.reset()

            this.visible = true
            this.$nextTick(() => {


            })
        },
        reset() {
            this.dataForm = {

            }
        },


        dataFormSubmit() {

            let check = true;
            if (this.dataForm.sampleId == "") {
                this.$refs['elForm'].validate((valid) => { check = valid })
            }
            if (check) {
                if (this.dataForm.detailData.length == 0) {
                    this.$message({
                        type: 'error',
                        message: '请添加检验项目',
                        duration: 1500,
                    })
                    return
                }
                this.$refs['tableForm'].validate((valid) => {
                    if (valid) {
                        this.btnLoading = true
                        addInspectionitem(this.dataForm).then((res) => {
                            this.btnLoading = false;
                            this.$message({
                                message: res.msg,
                                type: 'success',
                                duration: 1000,
                                onClose: () => {
                                    this.visible = false
                                    this.$emit('refresh', true)
                                }
                            })
                        }).catch((res) => {
                            this.btnLoading = false;
                        })
                    }
                });
            }
        }
    }
}
</script>